﻿package {

	import ga.wavaplayer.WAVAPlayer;
	import ga.wavaplayer.video.WVideo;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.system.Security;
	
	import com.adobe.serialization.json.JSON;
	
	import flash.net.NetConnection;
	import flash.net.NetStream;
	import flash.media.Video;
	import flash.events.NetStatusEvent;
	
    public class Main extends Sprite {		

		public var player:WAVAPlayer;
		
		public function Main() {
			loaderInfo.addEventListener(Event.COMPLETE, _stageLoadingCompleteHandler);
			
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
        }
		
		public function init():void {
			var options:Object = {
				width: stage.stageWidth,
				height: stage.stageHeight,
				video: {
					background: "http://i3.mfspics.com/scenes/523/768x432.jpg",
					url: 'http://trailers.realslutparty.com/lynn_roxy/vids/hd-trailers/rsp_lynn_roxy_trailer_768_700-hd.f4v',
					mode: WVideo.WVIDEO_MODE_HTTP
				},
				ui: {
					skinPath: 'http://mofos.guillaume.dev2.mansef.local/cdn/base/swf/'
				}
			}
			
			if(loaderInfo.parameters.options != undefined){
				var userInfo:Object = JSON.decode(loaderInfo.parameters.options);
				options.video.url = userInfo.video.url;
			}
			
			
			player = new WAVAPlayer(options);
			player.addEventListener(WAVAPlayer.READY, _playerReadyHandler);
		}
		
		private function _resizeHandler(e:Event):void {
			player.resize(stage.stageWidth, stage.stageHeight);
		}
		
		private function _stageLoadingCompleteHandler(e:Event):void {
			loaderInfo.removeEventListener(Event.COMPLETE, _stageLoadingCompleteHandler);
			init();
		}
		
		private function _playerReadyHandler(e:Event):void{
			player.removeEventListener(WAVAPlayer.READY, _playerReadyHandler);
			player.resize(stage.stageWidth, stage.stageHeight);
			this.addChild(player);
			
			stage.addEventListener(Event.RESIZE, _resizeHandler);
		}
    }
 }
